package Dao.DaoImpl;

import Dao.stustateDao;
import Utils.JDBCUtils;
import domain.OutApply;
import domain.stustate;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.Statement;
import java.util.Date;

public class stustateDaoImpl implements stustateDao {
    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());


    @Override
    public void updateStudentState(OutApply app,String isindorm) {
        System.out.println(app);
        String sql ="update stustate set isindorm=?,leftTime=? where stunum=?";
        template.update(sql,isindorm,app.getLeftTime(),app.getStunum());
    }

    @Override
    public void addStudentState(stustate stut) {
        String sql ="insert into stustate values(?,?,?,null,null)";
        template.update(sql,stut.getStunum(),stut.getName(),stut.getIsindorm());
    }

    @Override
    public void sign(String name,Date date,String flag) {
        System.out.println(name+date+flag);
        String sql ="update stustate set isindorm=?,intoTime=? where name=?";
        template.update(sql,flag,date,name);
    }

    @Override
    public stustate selectStutateByName(String name) {
        String sql = "select * from stustate where name=?";
        return template.queryForObject(sql,new BeanPropertyRowMapper<>(stustate.class),name);
    }
}
